package com.example.demo.controller;

import com.example.demo.entity.UserEntity;
import com.example.demo.pojo.User;
import com.example.demo.repository.UserRepository;
import com.example.demo.service.imp.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by qwesdfok on 2017/9/28.
 */
@Controller
@RequestMapping("/user")
@Api(value = "附件上传", tags = "附件上传")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    UserRepository userRepository;


    @RequestMapping("/")
    @ApiOperation(value = "图片上传到阿里云OSS")
    public String index(ModelMap map) {
        // 加入一个属性，用来在模板中读取
        map.addAttribute("name", "userName");
        map.addAttribute("bookTitle", "springBoot");
        // return模板文件的名称，对应src/main/resources/templates/welcome.html
        return "wellcome";
    }

    @RequestMapping(value = "/myId", method = RequestMethod.GET)
    public User mybatisView() {
        User user = userService.getUserById(87);

        return user;
    }

    @RequestMapping(value = "/jpaId", method = RequestMethod.GET)
    public List<UserEntity> view() {
        //spring data jpa //依赖 hibernate
        List<UserEntity> userEntity = new ArrayList<>();
      /*  userEntity = userRepository.findByUserName("沐风");*/
        userEntity.add(userRepository.findOne(87));
        return userEntity;
    }


}
